import { Entity, PrimaryGeneratedColumn, Column, ManyToOne,CreateDateColumn,UpdateDateColumn } from 'typeorm';
import { Order } from './order.entity';

export enum PaymentStatus {
  PENDING = 'PENDING',
  SUCCESS = 'SUCCESS',
  FAILED = 'FAILED'
}

export enum PaymentProvider {
  ALIPAY = 'ALIPAY',
  WECHAT = 'WECHAT'
}

@Entity('payment_record')
export class PaymentRecord {
  @PrimaryGeneratedColumn()
  id: number;

  @ManyToOne(() => Order)
  order: Order;

  @Column({ type: 'decimal', precision: 10, scale: 2 })
  amount: number;

  @Column({ type: 'enum', enum: PaymentProvider })
  provider: PaymentProvider;

  @Column({ type: 'enum', enum: PaymentStatus, default: PaymentStatus.PENDING })
  status: PaymentStatus;

  @Column({ nullable: true })
  transactionId: string;

  @Column({ type: 'timestamp', default: () => 'CURRENT_TIMESTAMP' })
     @CreateDateColumn()
  createdAt: Date;

  @Column({ type: 'timestamp', nullable: true })
     @UpdateDateColumn()
  updatedAt: Date;
}